/*
 * $Id$
 */
package corejs;

import java.util.Iterator;

/**
 *
 * @author myang
 */
public class StringsReader implements LineReader, Iterable<Line> {

   private final String[] _strings;
   private int _index;

   public StringsReader(final String... strings) {
      _strings = new String[strings.length];
      for (int i = 0; i < strings.length; ++i) {
         _strings[i] = strings[i];
      }
      _index = -1;
   }

   @Override
   public Line readLine() {
      return (++_index < _strings.length)
        ? new Line(1 + _index, _strings[_index]) : LineReaderSource.EOF_LINE;
   }

   public static void main(final String... args) {
      final StringsReader sr =
        new StringsReader("this is", "is", "a", "miracle!", "cool!", "can't",
        "you", "just", "believe", "it", "why!!!");
      for (final Line ln : sr) {
         System.out.println(ln);
      }
   }

   @Override
   public Iterator<Line> iterator() {
      return new Iterator() {
         private int _index;

         @Override
         public boolean hasNext() {
            return _index < _strings.length;
         }

         @Override
         public Line next() {
            ++_index;
            return readLine();
         }
         
         @Override
         public void remove() {
           
         }
      };
   }
}
